<!-- HTML header for doxygen 1.8.20-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=9"/>
	<meta name="generator" content="Doxygen 1.9.4"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>Raspberry Pi Pico SDK: include/hardware/boot_lock.h Source File</title>
	<!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="dynsections.js"></script>
	<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
	<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
	<link href="doxygen.css" rel="stylesheet" type="text/css" />
	<link href="normalise.css" rel="stylesheet" type="text/css"/>
<link href="main.css" rel="stylesheet" type="text/css"/>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
	<div class="navigation-mobile">
		<div class="logo--mobile">
			<a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
		</div>
		<div class="navigation-toggle">
			<span class="line-1"></span>
			<span class="line-2">
				<p>Menu Toggle</p>
			</span>
			<span class="line-3"></span>
		</div>
	</div>
	<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
		<div class="logo">
			<a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
			<span style="display: inline-block; margin-top: 10px;">
				v2.0.0
			</span>
		</div>
		<div class="navigation-footer">
			<img src="logo-mobile.svg" alt="Raspberry Pi">
			<a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
		</div>
<!-- 		<div class="search">
			<form>
				<input type="search" name="search" id="search" placeholder="Search">
				<input type="submit" value="Search">
			</form>
		</div> -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('boot__lock_8h_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle"><div class="title">boot_lock.h</div></div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span><span class="comment">/*</span></div>
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno">    2</span><span class="comment"> * Copyright (c) 2024 Raspberry Pi (Trading) Ltd.</span></div>
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno">    3</span><span class="comment"> *</span></div>
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno">    4</span><span class="comment"> * SPDX-License-Identifier: BSD-3-Clause</span></div>
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno">    5</span><span class="comment"> */</span></div>
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno">    6</span> </div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno">    7</span><span class="preprocessor">#ifndef _HARDWARE_BOOT_LOCK_H</span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno">    8</span><span class="preprocessor">#define _HARDWARE_BOOT_LOCK_H</span></div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno">    9</span> </div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span><span class="preprocessor">#include &quot;<a class="code" href="pico_8h.html">pico.h</a>&quot;</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span> </div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span><span class="comment">// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_HARDWARE_BOOT_LOCK, Enable/disable assertions in the hardware_boot_lock module, type=bool, default=0, group=hardware_boot_lock</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span><span class="preprocessor">#ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_BOOT_LOCK</span></div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span><span class="preprocessor">#define PARAM_ASSERTIONS_ENABLED_HARDWARE_BOOT_LOCK 0</span></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span> </div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span><span class="preprocessor">#if NUM_BOOT_LOCKS &gt; 0</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno">   18</span><span class="preprocessor">#include &quot;<a class="code" href="rp2__common_2hardware__sync_2include_2hardware_2sync_8h.html">hardware/sync.h</a>&quot;</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno">   19</span><span class="preprocessor">#include &quot;hardware/structs/bootram.h&quot;</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno">   20</span> </div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno">   24</span><span class="keyword">typedef</span> <span class="keyword">volatile</span> uint32_t boot_lock_t;</div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno">   25</span> </div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span><a class="code hl_define" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> <span class="keyword">static</span> boot_lock_t *boot_lock_instance(uint lock_num) {</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span>    invalid_params_if(HARDWARE_BOOT_LOCK, lock_num &gt;= NUM_BOOT_LOCKS);</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno">   34</span>    <span class="keywordflow">return</span> (boot_lock_t *) (BOOTRAM_BASE + BOOTRAM_BOOTLOCK0_OFFSET + lock_num * 4);</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span>}</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno">   36</span> </div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span><a class="code hl_define" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> <span class="keyword">static</span> uint boot_lock_get_num(boot_lock_t *lock) {</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span>    invalid_params_if(HARDWARE_BOOT_LOCK, (uint) lock &lt; BOOTRAM_BASE + BOOTRAM_BOOTLOCK0_OFFSET ||</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span>                            (uint) lock &gt;= NUM_BOOT_LOCKS * <span class="keyword">sizeof</span>(boot_lock_t) + BOOTRAM_BASE + BOOTRAM_BOOTLOCK0_OFFSET ||</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span>                            ((uint) lock - BOOTRAM_BASE + BOOTRAM_BOOTLOCK0_OFFSET) % <span class="keyword">sizeof</span>(boot_lock_t) != 0);</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span>    <span class="keywordflow">return</span> (uint) (lock - (boot_lock_t *) (BOOTRAM_BASE + BOOTRAM_BOOTLOCK0_OFFSET));</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span>}</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno">   49</span> </div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno">   55</span><a class="code hl_define" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> <span class="keyword">static</span> <span class="keywordtype">void</span> boot_lock_unsafe_blocking(boot_lock_t *lock) {</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno">   56</span>    <span class="comment">// Note we don&#39;t do a wfe or anything, because by convention these boot_locks are VERY SHORT LIVED and NEVER BLOCK and run</span></div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span>    <span class="comment">// with INTERRUPTS disabled (to ensure that)... therefore nothing on our core could be blocking us, so we just need to wait on another core</span></div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno">   58</span>    <span class="comment">// anyway which should be finished soon</span></div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno">   59</span>    <span class="keywordflow">while</span> (__builtin_expect(!*lock, 0)) { <span class="comment">// read from bootlock register (tries to acquire the lock)</span></div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno">   60</span>        <a class="code hl_function" href="group__pico__platform.html#gab0d1ba75ceb64131e19f613d7a5313c9">tight_loop_contents</a>();</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span>    }</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span>    <a class="code hl_function" href="group__hardware__sync.html#gaac3457fdba1624e5f45e7f936ad68049">__mem_fence_acquire</a>();</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span>}</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span> </div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno">   70</span><a class="code hl_define" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> <span class="keyword">static</span> <span class="keywordtype">bool</span> boot_try_lock_unsafe(boot_lock_t *lock) {</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno">   71</span>    <span class="keywordflow">if</span> (*lock) {</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span>        <a class="code hl_function" href="group__hardware__sync.html#gaac3457fdba1624e5f45e7f936ad68049">__mem_fence_acquire</a>();</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span>        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno">   74</span>    }</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span>    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>}</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span> </div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span><a class="code hl_define" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> <span class="keyword">static</span> <span class="keywordtype">void</span> boot_unlock_unsafe(boot_lock_t *lock) {</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span>    <a class="code hl_function" href="group__hardware__sync.html#ga1a9f3cba87fe49a3907a1535b9adfa3f">__mem_fence_release</a>();</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span>    *lock = 0; <span class="comment">// write to bootlock register (release lock)</span></div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span>}</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span> </div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span><a class="code hl_define" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> <span class="keyword">static</span> uint32_t boot_lock_blocking(boot_lock_t *lock) {</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span>    uint32_t save = <a class="code hl_function" href="group__hardware__sync.html#ga15ada9cfb92615e5bb05a29aa3fc7ad8">save_and_disable_interrupts</a>();</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span>    boot_lock_unsafe_blocking(lock);</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno">   99</span>    <span class="keywordflow">return</span> save;</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno">  100</span>}</div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno">  101</span> </div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span><span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">bool</span> is_boot_locked(boot_lock_t *lock) {</div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno">  108</span>    check_hw_size(boot_lock_t, 4);</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno">  109</span>    uint lock_num = boot_lock_get_num(lock);</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno">  110</span>    <span class="keywordflow">return</span> 0 != (*(io_ro_32 *) (BOOTRAM_BASE + BOOTRAM_BOOTLOCK_STAT_OFFSET) &amp; (1u &lt;&lt; lock_num));</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno">  111</span>}</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno">  112</span> </div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno">  123</span><a class="code hl_define" href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a> <span class="keyword">static</span> <span class="keywordtype">void</span> boot_unlock(boot_lock_t *lock, uint32_t saved_irq) {</div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno">  124</span>    boot_unlock_unsafe(lock);</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span>    <a class="code hl_function" href="group__hardware__sync.html#ga4bb69d1717ab90105ea05b82291fc0c7">restore_interrupts_from_disabled</a>(saved_irq);</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span>}</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno">  127</span> </div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno">  136</span>boot_lock_t *boot_lock_init(uint lock_num);</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno">  137</span> </div>
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno">  141</span><span class="keywordtype">void</span> boot_locks_reset(<span class="keywordtype">void</span>);</div>
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno">  142</span> </div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno">  143</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno">  144</span><span class="preprocessor">#endif</span></div>
<div class="ttc" id="agroup__hardware__sync_html_ga15ada9cfb92615e5bb05a29aa3fc7ad8"><div class="ttname"><a href="group__hardware__sync.html#ga15ada9cfb92615e5bb05a29aa3fc7ad8">save_and_disable_interrupts</a></div><div class="ttdeci">static __force_inline uint32_t save_and_disable_interrupts(void)</div><div class="ttdoc">Save and disable interrupts.</div><div class="ttdef"><b>Definition:</b> sync.h:206</div></div>
<div class="ttc" id="agroup__hardware__sync_html_ga1a9f3cba87fe49a3907a1535b9adfa3f"><div class="ttname"><a href="group__hardware__sync.html#ga1a9f3cba87fe49a3907a1535b9adfa3f">__mem_fence_release</a></div><div class="ttdeci">static __force_inline void __mem_fence_release(void)</div><div class="ttdoc">Release a memory fence.</div><div class="ttdef"><b>Definition:</b> sync.h:189</div></div>
<div class="ttc" id="agroup__hardware__sync_html_ga4bb69d1717ab90105ea05b82291fc0c7"><div class="ttname"><a href="group__hardware__sync.html#ga4bb69d1717ab90105ea05b82291fc0c7">restore_interrupts_from_disabled</a></div><div class="ttdeci">static __force_inline void restore_interrupts_from_disabled(uint32_t status)</div><div class="ttdoc">Restore interrupts to a specified state with restricted transitions.</div><div class="ttdef"><b>Definition:</b> sync.h:249</div></div>
<div class="ttc" id="agroup__hardware__sync_html_gaac3457fdba1624e5f45e7f936ad68049"><div class="ttname"><a href="group__hardware__sync.html#gaac3457fdba1624e5f45e7f936ad68049">__mem_fence_acquire</a></div><div class="ttdeci">static __force_inline void __mem_fence_acquire(void)</div><div class="ttdoc">Acquire a memory fence.</div><div class="ttdef"><b>Definition:</b> sync.h:173</div></div>
<div class="ttc" id="agroup__pico__platform_html_ga23eadd8d1642fb8fe4600708c36e116a"><div class="ttname"><a href="group__pico__platform.html#ga23eadd8d1642fb8fe4600708c36e116a">__force_inline</a></div><div class="ttdeci">#define __force_inline</div><div class="ttdoc">Attribute to force inlining of a function regardless of optimization level.</div><div class="ttdef"><b>Definition:</b> compiler.h:125</div></div>
<div class="ttc" id="agroup__pico__platform_html_gab0d1ba75ceb64131e19f613d7a5313c9"><div class="ttname"><a href="group__pico__platform.html#gab0d1ba75ceb64131e19f613d7a5313c9">tight_loop_contents</a></div><div class="ttdeci">static __force_inline void tight_loop_contents(void)</div><div class="ttdoc">No-op function for the body of tight loops.</div><div class="ttdef"><b>Definition:</b> platform.h:67</div></div>
<div class="ttc" id="apico_8h_html"><div class="ttname"><a href="pico_8h.html">pico.h</a></div></div>
<div class="ttc" id="arp2__common_2hardware__sync_2include_2hardware_2sync_8h_html"><div class="ttname"><a href="rp2__common_2hardware__sync_2include_2hardware_2sync_8h.html">sync.h</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->

	<script src="main.js"></script>
</body>
</html>